/**
  ETFRoot project, Anyang Normal University && IMP-CAS
  \class ETFAmplitudeChannel
  \brief abstract base class for a general raw data channel
  \author SUN Yazhou, asia.rabbit@163.com
  \since 2021-09-27
  \date 2021-09-27 last modified
  \attention
  changelog
  <table>
  <tr>  <th>Date        <th>Author      <th>Description                    </tr>
  <tr>  <td>2021-09-27   <td>Asia Sun    <td>file created                   </tr>
  </table>

  \copyright Copyright (c) 2021 Anyang Normal U. && IMP-CAS with LGPLv3 LICENSE
*/

#include <iostream>
#include "ETFAmplitudeChannel.h"
#include "ETFMsg.h"

using std::cout;
using std::endl;

ClassImp(ETFAmplitudeChannel);

ETFAmplitudeChannel::ETFAmplitudeChannel() : ETFRawChannel(){
  Initialize();
} // end ctor

ETFAmplitudeChannel::ETFAmplitudeChannel(const ETFAmplitudeChannel &ach)
  : ETFRawChannel(ach), fAmplitudes(ach.fAmplitudes){}

ETFAmplitudeChannel::~ETFAmplitudeChannel(){}

void ETFAmplitudeChannel::SetAmplitude(int amp, int i){
  if(fAmplitudes.size() == i) AddAmplitude(amp);
  else if(fAmplitudes.size() > i) fAmplitudes[i] = amp + rand0_1();
  else ETFMsg::Error("ETFAmplitudeChannel", "SetAmplitude: Requested subscipt out of bounds");
} // end member function SetAmplitude

void ETFAmplitudeChannel::AddAmplitude(int amp){
  fAmplitudes.push_back(amp + rand0_1());
} // end member function AddAmplitude

void ETFAmplitudeChannel::Reset(){
  ETFRawChannel::Reset();
  fAmplitudes.clear();
} // end member function Reset

void ETFAmplitudeChannel::Print() const{
  cout << "\033[34;1mAmplitude Channel, Channel ID: " << fChannelId << "\n\033[0m";
  for(const auto &v : fAmplitudes) cout << v << endl;
} // end member function Print
